package org.ydsw.data.manage.config;


import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ru.yandex.clickhouse.ClickHouseDataSource;
import ru.yandex.clickhouse.settings.ClickHouseProperties;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * clickhouse 连接配置类
 * @author admin
 */
@Configuration
@Data
public class ClickhouseConfig {
    @Value("${spring.clickhouse.url}")
    private String chAddr;

    @Value("${spring.clickhouse.user}")
    private String chUser;

    @Value("${spring.clickhouse.password}")
    private String chPass;

    @Bean
    public Connection getChClient() throws ClassNotFoundException, SQLException {
        Connection connection = null;
        Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
//        Class.forName("com.github.housepower.jdbc.ClickHouseDriver");

        if (chPass.equals("doNotHavePassword")){
           connection = DriverManager.getConnection(chAddr);
            return connection;
        }else {
            connection = DriverManager.getConnection(chAddr,chUser,chPass);
            return connection;
        }

    }

}
